﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using BBServer20210601.Pages;


namespace LayuiDemo.demo.ViewModels.FooVMs
{
	public partial class FooListVM : BasePagedListVM<Foo_View, FooSearcher>
	{
		protected override List<GridAction> InitGridAction()
		{
			return new List<GridAction>
			{
				this.MakeStandardAction("Foo", GridActionStandardTypesEnum.Create, Localizer["Sys.Create"],"demo", dialogWidth: 800),
				this.MakeStandardAction("Foo", GridActionStandardTypesEnum.Edit, Localizer["Sys.Edit"], "demo", dialogWidth: 800),
				this.MakeStandardAction("Foo", GridActionStandardTypesEnum.Delete, Localizer["Sys.Delete"], "demo", dialogWidth: 800),
				this.MakeStandardAction("Foo", GridActionStandardTypesEnum.Details, Localizer["Sys.Details"], "demo", dialogWidth: 800),
				this.MakeStandardAction("Foo", GridActionStandardTypesEnum.BatchEdit, Localizer["Sys.BatchEdit"], "demo", dialogWidth: 800),
				this.MakeStandardAction("Foo", GridActionStandardTypesEnum.BatchDelete, Localizer["Sys.BatchDelete"], "demo", dialogWidth: 800),
				this.MakeStandardAction("Foo", GridActionStandardTypesEnum.Import, Localizer["Sys.Import"], "demo", dialogWidth: 800),
				this.MakeStandardAction("Foo", GridActionStandardTypesEnum.ExportExcel, Localizer["Sys.Export"], "demo"),
			};
		}


		protected override IEnumerable<IGridColumn<Foo_View>> InitGridHeader()
		{
			return new List<GridColumn<Foo_View>>{
				this.MakeGridHeader(x => x.Age,100).SetSort(),
				this.MakeGridHeader(x => x.DepartType,100),
				this.MakeGridHeader(x => x.IsValid,100),
				this.MakeGridHeader(x => x.Name,100),
				this.MakeGridHeader(x => x.Remark),
				this.MakeGridHeaderAction(width: 200)
			};
		}

		public override IOrderedQueryable<Foo_View> GetSearchQuery()
		{
			var query = DC.Set<Foo>()
				.CheckEqual(Searcher.Age, x => x.Age)
				.CheckEqual(Searcher.DepartType, x => x.DepartType)
				.CheckEqual(Searcher.IsValid, x => x.IsValid)
				.CheckContain(Searcher.Name, x => x.Name)
				.CheckContain(Searcher.Remark, x => x.Remark)
				.Select(x => new Foo_View
				{
					ID = x.ID,
					Age = x.Age,
					DepartType = x.DepartType,
					IsValid = x.IsValid,
					Name = x.Name,
					Remark = x.Remark,
				})
				.OrderBy(x => x.ID);
			return query;
		}

	}

	public class Foo_View : Foo
	{

	}
}
